#! /usr/bin/env python2
# -*- coding: utf-8 -*-

# pip2 install web.py==0.51
import web

import sys
import os

urls = (
    '/(.*)', 'index'
)


class index:
    """默认请求"""

    def __init__(self):
        self.logger = web.ctx.environ['wsgilog.logger']

    def GET(self, param):
        """
        curl http://localhost:8080/value
        :param param:
        :return:
        """

        # 配置默认值
        if not param:
            param = 'world'
            pass

        self.logger.info("param : %s" % param)
        func("args")
        return 'hello,' + param + '!'

    pass


pass


def func(args):
    """函数日志"""
    try:
        logger = web.ctx.environ['wsgilog.logger']
        logger.info("func args : %s" % args)
        # 测试异常日志
        print(0 / 0)
    except Exception as e:
        logger.exception(e, stack_info=True)
    pass


if __name__ == "__main__":
    web.config.debug = True
    # web.internalerror = web.debugerror
    # web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
    # curl http://localhost:8080/
    app = web.application(urls, globals())
    app.run()

pass
